<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.List"%>
<%@ page isELIgnored="false" %> <%--isELIgnored=true禁用EL表达式--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>商品详情</title>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/main.css">
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.min-2.1.1.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/layui-v2.6.13/layui/css/layui.css">
</head>
<body>
	<div class="header_con">
		<div class="header">
			<div class="fr">

				<div class="login_btn fl">
				    欢迎您：<em>${user.uName}</em>
                    <span>|</span>
					<a href="/user/loginPage">注销</a>
					<span>|</span>
					<a href="/user/registerPage">注册</a>
				</div>
				<div class="user_link fl">
					<span>|</span>
					<a href="/user/centerPage">用户中心</a>
					<span>|</span>
					<a href="cartPage?uId=${user.id}">我的购物车</a>
					<span>|</span>
					<a href="/user/centerOrderPage">我的订单</a>
				</div>
			</div>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<a href="/shop/list" class="logo fl"><img src="<%=request.getContextPath() %>/images/logo1.png" style="width: 125px;height: 80px;"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索" style="background-color: silver;">
		</div>

	</div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1 style="background-color: silver;">全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="#" class="tshirt">新鲜水果</a></li>
					<li><a href="#" class="skirt">海鲜水产</a></li>
					<li><a href="#" class="pants">猪牛羊肉</a></li>
					<li><a href="#" class="clothes">禽类蛋品</a></li>
					<li><a href="#" class="winter">新鲜蔬菜</a></li>
					<li><a href="#" class="head">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="/shop/list">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img src="http://localhost:8887/${good.imgUrl}"></div>

		<div class="goods_detail_list fr">
			<h3>${good.gName}</h3>
			<p>潮流简约 · 享受生活</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>${good.gPrice}</em></span>
				<span class="show_unit">单  位：件</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：${good.gCount}</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1" id="sum">

					<input type="button" id="btn" class="add fr" value="+" style="height:50%" >
					<input type="button" id="btn2" class="minus fr" value="-" style="height:50%">
				</div> 
			</div>
			<div class="total">
			    <div class="layui-inline">
			    <em>总价格：￥</em>
			    </div>
			    <div class="layui-inline"> <input class="layui-input" value="${good.gPrice}"  style="background:transparent;border:1px solid #ffffff;font-size: 20px;" readonly" id="count"></div>

			</div>
			<div class="operate_btn">
				<a href="#" onclick="add_order()" class="buy_btn" id="add_order">立即购买</a>
				<a href="#" onclick="add_cart()" class="add_cart" id="add_cart">加入购物车</a>
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">

		</div>


	</div>
	<div class="footer">
		<div class="foot_link">
			<a href="#">张旭光太胖</a>
			<span>|</span>
			<a href="#">张旭光太丑</a>
			<span>|</span>
			<a href="#">张旭光太虚</a>
			<span>|</span>
			<a href="#">健脑补肾丸</a>
		</div>
		<p> 北京旭光补肾技术有限公司 </p>
		<p>电话：541885418828    京ICP备*******8号</p>
	</div>
	<script>

        var sum = $("#sum").val();
        var count = $("count").val();
	    $("#btn").click(function (){
	        sum++;
	        console.info(sum);
	       $("#sum").attr("value", sum);
	       $("#count").attr("value", sum*${good.gPrice});

	    })
        $("#btn2").click(function (){

            if(sum<=1){
                sum = 1;
            }else{
                sum--;
            }
            $("#sum").attr("value", sum);
            $("#count").attr("value", sum*${good.gPrice});
            console.info(sum);
            console.info(${good.gPrice});
        })

        function add_cart(){
            var count = $("#sum").val();
			var remainder=${good.gCount}-count;
            var params ="gId="+${good.id}+"&buyCount="+count+"&uId="+${user.id}+"&gCount="+remainder+"&id="+${good.id};
            console.info(params);
            $.ajax({
                url:"addCart",
                data:params,
                type:"post",
                success:function(str){
                    if(str=="0"){
                        alert("加入购物车失败");
                    }else{
                        alert("加入购物车成功");
                        parent.location.reload();
                    }
                }
            })
        }

        function add_order(){
            var orderMoney = ${good.gPrice} * $("#sum").val();
            var remainder=${good.gCount} - $("#sum").val();
            var params = "id="+${good.id}+"&buyCount="+$("#sum").val()+"&gCount="+remainder+"&orderMoney="+orderMoney+"&uId="+${user.id}+"&gPrice="+${good.gPrice};

            console.info(params);
            $.ajax({
                url:"order",
                data:params,
                type:"post",
                success:function (str){
                    if(str=="0"){
                        alert("生成订单失败");


                    }else{
                        console.info("id="+${good.id}+"&buyCount="+$("#sum").val()+"&orderNo="+str);
                        alert("生成订单成功");

                        window.location.href="orderPage?id="+${good.id}+"&buyCount="+$("#sum").val()+"&orderNo="+str;
                    }
                }
            })
        }
	</script>
	
</body>
</html>